package com.m.IO.Chars;

import java.io.*;

/**
 * 转换流      OutputStreamWriter  /   InputStreamReader
 * 可以将字节流转换为字符流。
 * 可以设置字符的编码方式
 *
 * @author Mc.Chai
 * @program: Java基础
 * @create 2021-11-22-18:01 18:01
 */
public class TestConvertStream {
    public static void main(String[] args) throws IOException {
        //原来持有字节输出流
        OutputStream outputStream=new FileOutputStream("convert.txt");
        //将字节流转换为字符流
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream,"GBK");
        //将字符流进行再次包装
        PrintWriter printWriter = new PrintWriter(outputStream);
        printWriter.println("你好");
        printWriter.println("世界");
        printWriter.close();    //关闭流

        FileInputStream fileInputStream=new FileInputStream("convert.txt");
        InputStreamReader inputStreamReader=new InputStreamReader(fileInputStream,"GBK");   //设置解码方式
        BufferedReader bufferedReader=new BufferedReader(inputStreamReader);

        while (true){
            String s=bufferedReader.readLine();
            if (s==null) break;
            System.out.println(s);

        }


    }
}
